﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConceptionLogiciel_Devoir1
{
    class Facture
    {
        private double prixLocation;
        private double depotGarantie;
        private double assurance;
        private double fraisKm;
        private double fraisRetard;
        private double rabais;
        private double sousTotal;
        private double tps;
        private double tvq;
        private double total;

        private double montantPaiement;
        private DateTime datePaiement;
        private string methodePaiement;

        public Facture() 
        {
            this.prixLocation = 0.00;
            this.depotGarantie = 0.00;
            this.assurance = 0.00;
            this.fraisKm = 0.00;
            this.fraisRetard = 0.00;
            this.rabais = 0.00;
            this.sousTotal = 0.00;
            this.tps = 0.00;
            this.tvq = 0.00;
            this.total = 0.00;

            this.montantPaiement = 0.00;
        }

        // Get && set
        // -------------------------------------------------------------------------------
        public double PrixLocation
        {
            get { return prixLocation; }
            set { this.prixLocation = value; }
        }
        public double DepotGarantie
        {
            get { return depotGarantie; }
            set { this.depotGarantie = value; }
        }
        public double Assurance
        {
            get { return assurance; }
            set { this.assurance = value; }
        }
        public double SousTotal
        {
            get { return sousTotal; }
            set { this.sousTotal = value; }
        }
        public double Tps
        {
            get { return tps; }
            set { this.tps = value; }
        }
        public double Tvq
        {
            get { return tvq; }
            set { this.tvq = value; }
        }
        public double Total
        {
            get { return total; }
            set { this.total = value; }
        }

        // Facture pour les locations
        // -------------------------------------------------------------------------------
        public void factureLocation(double _prixLocation, double _depotGarantie, double _assurance)
        {
            this.prixLocation = _prixLocation;
            this.depotGarantie = _depotGarantie;
            this.assurance = _assurance;
        }

        public void factureRetour(double _fraisKm, double _fraisRetard, double _rabais)
        {
            this.fraisKm = _fraisKm;
            this.fraisRetard = _fraisRetard;
            this.rabais = _rabais;
        }

        public void paiement(string _methodePaiement, double _montantPaiement)
        {
            this.methodePaiement = _methodePaiement;
            this.montantPaiement += _montantPaiement;
            this.datePaiement = DateTime.Now;
        }

        private void setSousTotal()
        {
            this.sousTotal = this.prixLocation + this.depotGarantie + this.assurance +this.fraisKm + this.fraisRetard - this.rabais;
        }

        private void setTaxes()
        {
            this.tps = this.sousTotal * 0.0975;
            this.tvq = this.sousTotal * 0.05;
        }

        public void setTotal()
        {
            this.setSousTotal();
            this.setTaxes();

            this.total = this.tps + this.tvq + this.sousTotal;
        }

        public double Rabais
        {
            get { return this.rabais; }
        }

        public double FraisKm
        {
            get { return this.fraisKm; }
        }

        public double FraisRetard
        {
            get { return this.fraisRetard; }
        }

        public double getBalance()
        {
            if (this.total == 0.00)
                setTotal();

            return (this.total - this.montantPaiement);
        }

        public override string ToString()
        {
            setTotal(); // calculer le soustotal, taxes et total avant d'afficher

            string s = "";
            s += "Prix de location: " + String.Format("{0:C}", this.prixLocation) +" \n";
            s += "Assurance: " + this.assurance + "\n\n";

            s += "Depot de garantie: -(" + String.Format("{0:C}", this.depotGarantie) + ") \n";

            s += "Solde du client : " + String.Format("{0:C}", (this.total - this.montantPaiement)) + " \n\n";

            s += "Frais de kilometrage: " + String.Format("{0:C}", this.fraisKm) + " \n";
            s += "Frais de retard: " + this.fraisRetard + " \n\n";

            s += "Rabais: -(" + String.Format("{0:C}", this.rabais) + ") \n\n";

            s += "Sous-Total: " + String.Format("{0:C}", this.sousTotal) + " \n";

            s += "TPS: " + String.Format("{0:C}", this.tps) + " \n";
            s += "TVQ: " + String.Format("{0:C}", this.tvq) + " \n";

            s += "Total: " + String.Format("{0:C}", this.total);

            return s;
        }
    }
}
